//
//  WMPickerView.swift
//  WMToolsDemo
//
//  Created by WTFSSD on 2016/12/13.
//  Copyright © 2016年 WTFSSD. All rights reserved.
//

import UIKit

typealias WMPickerViewBlock = (WMPickerView ,Int,Int)->Void
class WMPickerView: UIView,UIPickerViewDelegate,UIPickerViewDataSource {
    lazy var pickerView :UIPickerView = {
        let v = UIPickerView.init(frame: CGRect.init());
        v.delegate = self
        v.dataSource = self
        v.backgroundColor = UIColor.HexColor("#eeeeee")
        return v
    }()
    
    var didSelectedData  = WMPickerViewBlock?()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        addSubview(pickerView)
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func layoutSubviews() {
        super.layoutSubviews();
        pickerView.frame = bounds;
    }
    
    
    func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int {
        return 3;
    }
    
    func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
        return 3;
    }
    
    func pickerView(pickerView: UIPickerView, rowHeightForComponent component: Int) -> CGFloat {
        return 30;
    }
    
    func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
        let str :NSString = ""
        return str.add(component).add("->").add(row)
    }
    
    func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
        if (self.didSelectedData != nil) {
            self.didSelectedData!(self,component,row)
        }
    }
    
    
}
